package top.humbleyuan.greedy;

import java.util.Arrays;
import java.util.LinkedList;

/**
 * @Author HumbleYuan
 * @Date 2020/5/18 20:17
 * @Des 根据身高重建队列
 */
public class LeetCode_406 {
    public static void main(String[] args) {
        int[][] people = {{7,0}, {4,4}, {7,1}, {5,0}, {6,1}, {5,2}};

        /**
         * # 高度相同按序号排就行
         * # 高度不同先排高的
         */

        Arrays.sort(people, (a1, a2) -> a1[0] == a2[0] ? a1[1] - a2[1] : a2[0] - a1[0]);

        // 按顺序插入
        LinkedList<int[]> list = new LinkedList<>();

        for (int i = 0; i < people.length; i++) {
            list.add(people[i][1], people[i]);
        }

        int[][] res = new int[people.length][2];
        int i = 0;
        for (int[] arr : list) {
            res[i++] = arr;
        }
    }
}
